import { defHttp } from '@/utils/http/axios';
import {
  TemplateInfo,
  TemplateParams,
  TemplateListGetResultModel,
  TemplateAddReq,
  TemplateEditReq,
  TemplateDelReq,
} from './model/templateModel';

enum Api {
  List = '/api/admin/v1/template/list',
  Create = '/api/admin/v1/template/add',
  Update = '/api/admin/v1/template/edit',
  Delete = '/api/admin/v1/template/del',
  Info = '/api/admin/v1/template/info',
}

/**
 * @description: 获取模板列表
 */
export const getTemplateList = (params: TemplateParams) =>
  defHttp.get<TemplateListGetResultModel>({
    url: Api.List,
    params,
    headers: { 'Content-Type': 'multipart/form-data' },
  });

/**
 * @description: 创建模板
 */
export const createTemplate = (params: TemplateAddReq) =>
  defHttp.post<{ id: number }>({ url: Api.Create, params });

/**
 * @description: 更新模板
 */
export const updateTemplate = (params: TemplateEditReq) =>
  defHttp.put<void>({ url: Api.Update, params });

/**
 * @description: 删除模板
 */
export const deleteTemplate = (params: TemplateDelReq) =>
  defHttp.delete<void>({ url: Api.Delete, params });

/**
 * @description: 获取模板详情
 */
export const getTemplateInfo = (id: number) =>
  defHttp.get<TemplateInfo>({ url: Api.Info, params: { id } });
